﻿// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "GameplayEffectTypes.h"
#include "GameFramework/Actor.h"
#include "Projectile.generated.h"

class UNiagaraSystem;
class UProjectileMovementComponent;
class USphereComponent;

UCLASS()
class AURA_API AProjectile : public AActor
{
	GENERATED_BODY()

public:

	AProjectile();

	/** 伤害GE句柄 */
	UPROPERTY(BlueprintReadWrite, meta=(ExposeOnSpawn = true))
	FGameplayEffectSpecHandle DamageEffectHandle;

protected:

	virtual void BeginPlay() override;

	virtual void Destroyed() override;

	/** 碰撞球体指针 */
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
	TObjectPtr<USphereComponent> Sphere;

private:

	// ----------------------------------------------------------------------------------------------------------------
	//	组件和属性相关
	// ----------------------------------------------------------------------------------------------------------------

	UFUNCTION()
	void OnSphereOverlap(
		UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp,
		int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult
	);

	UPROPERTY(VisibleAnywhere)
	TObjectPtr<UProjectileMovementComponent> ProjectileMovement;

	UPROPERTY(EditAnywhere,meta=(DisplayPriority = -1))
	TObjectPtr<UNiagaraSystem> ImpactVFX;

	UPROPERTY(EditAnywhere,meta=(DisplayPriority = -1))
	TObjectPtr<USoundBase> ImpactSFX;

	/** 当前是否重叠命中 */
	bool bHit = false;

	/** 播放表现效果 */
	void PlayAfterImpacted() const;

	/** 移动循环音效指针 */
	UPROPERTY(EditAnywhere)
	TObjectPtr<USoundBase> LoopingSound;

	/** 循环音效组件指针，后续用于删除 */
	UPROPERTY()
	TObjectPtr<UAudioComponent> LoopingSoundComponent;

	/** Actor的存在时间(LifeSpan: 寿命) */
	UPROPERTY(EditAnywhere)
	float LifeSpan = 15.f;
};
